home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vblha1 / main.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-07  |  14.7 KB  |  545 lines

  1. VERSION 2.00
  2. Begin Form frmMain 
  3.    ClientHeight    =   4035
  4.    ClientLeft      =   375
  5.    ClientTop       =   1920
  6.    ClientWidth     =   8625
  7.    Height          =   4770
  8.    Left            =   315
  9.    LinkTopic       =   "Form2"
  10.    ScaleHeight     =   4035
  11.    ScaleWidth      =   8625
  12.    Top             =   1245
  13.    Width           =   8745
  14.    Begin PictureBox picStatus 
  15.       Align           =   2  'Align Bottom
  16.       BackColor       =   &H00C0C0C0&
  17.       Height          =   255
  18.       Left            =   0
  19.       ScaleHeight     =   225
  20.       ScaleWidth      =   8595
  21.       TabIndex        =   3
  22.       Top             =   3780
  23.       Width           =   8625
  24.       Begin TextBox txtMemo 
  25.          BackColor       =   &H00C0C0C0&
  26.          Height          =   285
  27.          Left            =   3840
  28.          TabIndex        =   9
  29.          Top             =   0
  30.          Width           =   1335
  31.       End
  32.       Begin TextBox txtFname 
  33.          BackColor       =   &H00C0C0C0&
  34.          Height          =   285
  35.          Left            =   2640
  36.          TabIndex        =   6
  37.          Top             =   0
  38.          Width           =   1215
  39.       End
  40.       Begin TextBox txtName 
  41.          BackColor       =   &H00C0C0C0&
  42.          Height          =   285
  43.          Left            =   1200
  44.          TabIndex        =   5
  45.          Top             =   0
  46.          Width           =   1455
  47.       End
  48.       Begin TextBox txtID 
  49.          BackColor       =   &H00C0C0C0&
  50.          Height          =   285
  51.          Left            =   120
  52.          TabIndex        =   4
  53.          Top             =   0
  54.          Width           =   1095
  55.       End
  56.    End
  57.    Begin ComboBox cboID 
  58.       Height          =   300
  59.       Left            =   1320
  60.       Style           =   2  'Dropdown List
  61.       TabIndex        =   2
  62.       Top             =   120
  63.       Width           =   1815
  64.    End
  65.    Begin PictureBox PicControl 
  66.       Align           =   1  'Align Top
  67.       BackColor       =   &H00C0C0C0&
  68.       FillColor       =   &H00FFFFFF&
  69.       Height          =   495
  70.       Left            =   0
  71.       ScaleHeight     =   465
  72.       ScaleWidth      =   8595
  73.       TabIndex        =   1
  74.       Top             =   0
  75.       Width           =   8625
  76.       Begin TextBox txtFrom 
  77.          Height          =   285
  78.          Left            =   5760
  79.          TabIndex        =   13
  80.          Top             =   120
  81.          Width           =   1215
  82.       End
  83.       Begin TextBox txtSub 
  84.          Height          =   285
  85.          Left            =   3600
  86.          TabIndex        =   11
  87.          Top             =   120
  88.          Width           =   1575
  89.       End
  90.       Begin OptionButton optMemo 
  91.          BackColor       =   &H00C0C0C0&
  92.          Caption         =   "&Memo"
  93.          FontBold        =   0   'False
  94.          FontItalic      =   0   'False
  95.          FontName        =   "Arial"
  96.          FontSize        =   8.25
  97.          FontStrikethru  =   0   'False
  98.          FontUnderline   =   0   'False
  99.          Height          =   255
  100.          Left            =   600
  101.          TabIndex        =   10
  102.          Top             =   0
  103.          Width           =   1095
  104.       End
  105.       Begin OptionButton optName 
  106.          BackColor       =   &H00C0C0C0&
  107.          Caption         =   "&Name"
  108.          FontBold        =   0   'False
  109.          FontItalic      =   0   'False
  110.          FontName        =   "Arial"
  111.          FontSize        =   8.25
  112.          FontStrikethru  =   0   'False
  113.          FontUnderline   =   0   'False
  114.          Height          =   255
  115.          Left            =   120
  116.          TabIndex        =   8
  117.          Top             =   240
  118.          Width           =   735
  119.       End
  120.       Begin OptionButton optID 
  121.          BackColor       =   &H00C0C0C0&
  122.          Caption         =   "&ID"
  123.          FontBold        =   0   'False
  124.          FontItalic      =   0   'False
  125.          FontName        =   "Arial"
  126.          FontSize        =   8.25
  127.          FontStrikethru  =   0   'False
  128.          FontUnderline   =   0   'False
  129.          Height          =   255
  130.          Left            =   120
  131.          TabIndex        =   7
  132.          Top             =   0
  133.          Width           =   495
  134.       End
  135.       Begin Label lblFrom 
  136.          BackColor       =   &H00C0C0C0&
  137.          Caption         =   "From:"
  138.          Height          =   255
  139.          Left            =   5280
  140.          TabIndex        =   14
  141.          Top             =   120
  142.          Width           =   495
  143.       End
  144.       Begin Label lblSub 
  145.          BackColor       =   &H00C0C0C0&
  146.          Caption         =   "Sub:"
  147.          Height          =   255
  148.          Left            =   3240
  149.          TabIndex        =   12
  150.          Top             =   120
  151.          Width           =   375
  152.       End
  153.    End
  154.    Begin TextBox txtWorkarea 
  155.       BorderStyle     =   0  'None
  156.       Height          =   1815
  157.       Left            =   0
  158.       MultiLine       =   -1  'True
  159.       ScrollBars      =   3  'Both
  160.       TabIndex        =   0
  161.       Top             =   480
  162.       Width           =   3375
  163.    End
  164.    Begin Menu mnuFile 
  165.       Caption         =   "&File"
  166.       Begin Menu mnuNew 
  167.          Caption         =   "&New"
  168.       End
  169.       Begin Menu mnuOpen 
  170.          Caption         =   "&Open"
  171.       End
  172.       Begin Menu mnuSave 
  173.          Caption         =   "&Save"
  174.       End
  175.       Begin Menu mnuClose 
  176.          Caption         =   "&Close"
  177.       End
  178.       Begin Menu mnuSep1 
  179.          Caption         =   "-"
  180.       End
  181.       Begin Menu mnuFDelete 
  182.          Caption         =   "&Delete"
  183.       End
  184.       Begin Menu mnuTrash 
  185.          Caption         =   "&Trash"
  186.       End
  187.       Begin Menu mnuSep2 
  188.          Caption         =   "-"
  189.       End
  190.       Begin Menu mnuExit 
  191.          Caption         =   "E&xit"
  192.       End
  193.    End
  194.    Begin Menu mnuEdit 
  195.       Caption         =   "&Edit"
  196.       Begin Menu mnuCut 
  197.          Caption         =   "Cu&t"
  198.       End
  199.       Begin Menu mnuCopy 
  200.          Caption         =   "&Copy"
  201.       End
  202.       Begin Menu mnuPaste 
  203.          Caption         =   "&Paste"
  204.       End
  205.       Begin Menu mnuDelete 
  206.          Caption         =   "&Delete"
  207.       End
  208.    End
  209.    Begin Menu mnuView 
  210.       Caption         =   "&View"
  211.    End
  212.    Begin Menu mnuOptions 
  213.       Caption         =   "&Options"
  214.    End
  215. Option Explicit
  216. Dim TotalRec As Long
  217. Sub cboID_Click ()
  218. 'Update status bar
  219. procStatusBar
  220. End Sub
  221. Sub Form_Activate ()
  222. 'Update status bar
  223. procStatusBar
  224. 'Set file name to default
  225. If workfile.fopen = "" Then
  226.  frmMain.Caption = txtFname.Text
  227. End If
  228. End Sub
  229. 'Copyright 1995 by Hitoshi Ozawa
  230. Sub Form_Load ()
  231. ' Load the frmGetFile dialog box without displaying
  232. Load frmGetFile
  233. 'Initialize the cboFileType combo box of the frmGetFile
  234. frmGetFile.cboFileType.AddItem "Text files (*.txt)"
  235. frmGetFile.cboFileType.AddItem "All files (*.*)"
  236. frmGetFile.cboFileType.AddItem "LHA files (*.LZH)"
  237. frmGetFile.cboFileType.ListIndex = 0
  238. 'Initialize to ID selection
  239. optID.Value = True
  240. 'Initialize ID combo list
  241. procGetID
  242. End Sub
  243. Sub Form_Resize ()
  244. picControl.ScaleWidth = frmMain.ScaleWidth
  245. txtWorkArea.Width = frmMain.ScaleWidth
  246. txtWorkArea.Height = frmMain.ScaleHeight - picControl.ScaleHeight - picStatus.ScaleHeight
  247. End Sub
  248. 'Copyright 1995 by Hitoshi Ozawa
  249. Sub mnuClose_Click ()
  250. 'Clear text area
  251. txtWorkArea.Text = ""
  252. frmMain.Caption = ""
  253. 'Reset filenames
  254. workfile.lopen = ""
  255. workfile.fopen = ""
  256. 'Refresh frmGetfile
  257. frmGetFile.txtFileName.Text = ""
  258. frmGetFile.filFiles.Pattern = "*.txt"
  259. frmGetFile.filFiles.Refresh
  260. End Sub
  261. Sub mnuCopy_Click ()
  262. 'Clear the clipboard
  263. Clipboard.Clear
  264. 'Transfer to the clipboard
  265. Clipboard.SetText txtWorkArea.SelText
  266. End Sub
  267. Sub mnuCut_Click ()
  268. 'Clear the clipboard
  269. Clipboard.Clear
  270. 'Transfer to the clipboard
  271. Clipboard.SetText txtWorkArea.SelText
  272. 'Delete the current selected aread
  273. txtWorkArea.SelText = ""
  274. End Sub
  275. Sub mnuDelete_Click ()
  276. 'Delete selected area
  277. txtWorkArea.SelText = ""
  278. End Sub
  279. 'Copyright 1995 by Hitoshi Ozawa
  280. Sub mnuExit_Click ()
  281.   End
  282. End Sub
  283. Sub mnuFDelete_Click ()
  284.  procDel
  285. End Sub
  286. Sub mnuNew_Click ()
  287. 'Clear text area
  288. txtWorkArea.Text = ""
  289. frmMain.Caption = ""
  290. 'Reset filenames
  291. workfile.lopen = ""
  292. workfile.fopen = ""
  293. procStatusBar
  294. End Sub
  295. 'Copyright 1995 by Hitoshi Ozawa
  296. Sub mnuOpen_Click ()
  297. Dim retcode As Integer
  298. 'Initialize file name to null
  299. workfile.lopen = ""
  300. 'Display the frmGetFile as modal
  301. curForm = fGet
  302. frmGetFile.Show 1
  303. curForm = fMain
  304. 'Change file name in status bar
  305. txtFname.Text = workfile.fopen
  306. 'Change window caption
  307. If workfile.lopen = "" Then
  308.  frmMain.Caption = workfile.fopen
  309.  frmMain.Caption = workfile.lopen & "(" & workfile.fopen & ")"
  310. End If
  311. 'If not text file Execute file
  312. Select Case LCase$(Right$(frmGetFile.Tag, 3))
  313.  Case "exe"
  314.    retcode = Shell(frmGetFile.Tag, 1)
  315.  Case "com"
  316.    retcode = Shell(frmGetFile.Tag, 1)
  317.  Case "bat"
  318.    retcode = Shell(frmGetFile.Tag, 1)
  319.  Case "wri"
  320.    retcode = Shell("write.exe " & frmGetFile.Tag, 1)
  321.  Case Else   'if not any of above, treat at text file
  322.   'Get file number
  323.    FileNum = FreeFile
  324.    'Open file for input
  325.    If Len(frmGetFile.Tag) Then
  326.      Open frmGetFile.Tag For Binary As FileNum    ' open file for input
  327.      txtWorkArea.Text = Input$(LOF(FileNum), FileNum)
  328.      'Close file
  329.      Close FileNum
  330.    End If
  331. End Select
  332. End Sub
  333. Sub mnuPaste_Click ()
  334. 'Replace current selected area with content of clipboard
  335. txtWorkArea.SelText = Clipboard.GetText()
  336. End Sub
  337. 'Copyright 1995 by Hitoshi Ozawa
  338. Sub mnuSave_Click ()
  339. Dim retcode As Integer
  340. Dim curpath As String
  341. Dim cnt
  342. 'File name not entered - default to txtFname
  343. If frmGetFile.Tag = "" Then
  344.   workfile.lopen = ""
  345.   procMsave
  346.   Exit Sub
  347. End If
  348. If workfile.fopen = "" Then
  349.  procSave
  350.  Select Case LCase$(Right$(frmGetFile.Tag, 3))
  351.   Case "exe"
  352.    retcode = Shell(frmGetFile.Tag, 1)
  353.   Case "com"
  354.    retcode = Shell(frmGetFile.Tag, 1)
  355.   Case "bat"
  356.    retcode = Shell(frmGetFile.Tag, 1)
  357.   Case "wri"
  358.    retcode = Shell("write.exe " & frmGetFile.Tag, 1)
  359.   Case Else   'if not any of above, treat at text file
  360.    procSave
  361.  End Select
  362. End If
  363. 'Refresh file list
  364. frmGetFile.filFiles.Refresh
  365. End Sub
  366. Sub mnuTrash_Click ()
  367.   procTrash
  368. End Sub
  369. Sub optID_Click ()
  370. 'Recreate Combo IDs
  371. procGetID
  372. End Sub
  373. Sub optMemo_Click ()
  374. 'Recreate Combo IDs
  375. procGetID
  376. End Sub
  377. Sub optName_Click ()
  378. 'Recreate Combo IDs
  379. procGetID
  380. End Sub
  381. Sub procGetID ()
  382. Dim Person As PersonInfo
  383. Dim FileNum As Integer
  384. Dim RecordLen As Long
  385. Dim CurrentRecord As Long
  386. 'Clear Combo IDs
  387. cboID.Clear
  388. 'Calculate length of record
  389. RecordLen = Len(Person)
  390. 'Get a file number
  391. FileNum = FreeFile
  392. On Error GoTo NOID
  393. 'Open file from random access. Create file if doesn't exist
  394. Open "USERS.DAT" For Random As FileNum Len = RecordLen
  395. CurrentRecord = 1
  396. Do While Not EOF(FileNum)
  397.   Get #FileNum, CurrentRecord, Person
  398.   If optID.Value = True Then
  399.    cboID.AddItem Trim(Person.ID)
  400.   ElseIf optName.Value = True Then
  401.    cboID.AddItem Trim(Person.Name)
  402.   Else
  403.    cboID.AddItem Trim(Person.Memo)
  404.   End If
  405.   CurrentRecord = CurrentRecord + 1
  406. TotalRec = CurrentRecord
  407. 'Close file
  408. Close FileNum
  409. 'Set default to first ID
  410. cboID.ListIndex = 0
  411. NOID:
  412. Exit Sub
  413. End Sub
  414. Sub procMsave ()
  415. Dim retcode As Integer
  416. Dim curpath As String
  417. Dim cnt
  418. Dim savefile As String
  419. 'Get file number
  420. FileNum = FreeFile
  421. savefile = Trim(filedir.sdir) & txtFname.Text
  422. 'Open file for input
  423. Open savefile For Output As FileNum
  424. Print #FileNum, "TO:" & txtID.Text
  425. Print #FileNum, "SUB:" & txtSub.Text & Chr(10)
  426. If txtFrom.Text <> "" Then
  427.  Print #FileNum, "FROM:" & txtFrom.Text
  428. End If
  429. 'Output contents to text area
  430. Print #FileNum, txtWorkArea.Text
  431. 'Close file
  432. Close FileNum
  433. End Sub
  434. Sub procSave ()
  435. Dim retcode As Integer
  436. Dim curpath As String
  437. Dim cnt
  438.  'Get file number
  439.  FileNum = FreeFile
  440.  'Open file for input
  441.  Open frmGetFile.Tag For Output As FileNum
  442.  'Output contents to text area
  443.  Print #FileNum, txtWorkArea.Text
  444.  'Close file
  445.  Close FileNum
  446. 'If it was a LZH file, update LZH file and delete text file
  447. If workfile.lopen <> "" Then
  448.  'Save current path
  449.  curpath = CurDir
  450.  'Reset buffer size
  451.  buffer = Space(szbuff)
  452.  ChDrive Mid$(frmGetFile.Tag, 1, 2)
  453.  ChDir frmGetFile.filFiles.Path
  454. 'Create LHA command
  455.  cmd = "a " & workfile.lopen & " " & workfile.fopen
  456.  'Perform LHA operation
  457.  retcode = lha(cmd, buffer, szbuff)
  458.  'Check for error
  459.  If retcode <> 0 Then
  460.   MsgBox ("Refresh error: " & retcode)
  461.   Exit Sub
  462.  End If
  463.  'Delete extracted file
  464.  Kill workfile.fopen
  465.  'Return to original drive
  466.  ChDrive Mid$(curpath, 1, 2)
  467.  'Return to original path
  468.  ChDir curpath
  469. End If
  470. End Sub
  471. Sub procStatusBar ()
  472. Dim Person As PersonInfo
  473. Dim FileNum As Integer
  474. Dim RecordLen As Long
  475. Dim today
  476. 'Calculate length of record
  477. RecordLen = Len(Person)
  478. 'Get a file number
  479. FileNum = FreeFile
  480. On Error GoTo STERRORID
  481. 'Open file from random access. Create file if doesn't exist
  482. Open "USERS.DAT" For Random As FileNum Len = RecordLen
  483. Get #FileNum, cboID.ListIndex + 1, Person
  484. 'Update status bar
  485. txtID.Text = Trim(Person.ID)
  486. txtName.Text = Trim(Person.Name)
  487. txtMemo.Text = Trim(Person.Memo)
  488. 'If there is no file name
  489. If workfile.fopen = "" Then
  490.  'Build filename using today's date
  491.  today = Now
  492.  txtFname.Text = Trim(Person.Fname) & Format(today, "yymmdd") & "." & Trim(Person.Fext)
  493.  'Reset Header filename
  494.  frmMain.Caption = txtFname.Text
  495. End If
  496. 'Close file
  497. Close FileNum
  498. STERRORID:
  499. Exit Sub
  500. End Sub
  501. Sub procWriteID ()
  502. Dim Person As PersonInfo
  503. Dim FileNum As Integer
  504. Dim RecordLen As Long
  505. Dim pos
  506. 'Calculate length of record
  507. RecordLen = Len(Person)
  508. 'Get a file number
  509. FileNum = FreeFile
  510. On Error GoTo WRERRORID
  511. 'Open file from random access. Create file if doesn't exist
  512. Open "USERS.DAT" For Random As FileNum Len = RecordLen
  513. 'Set record
  514. Person.ID = txtID.Text
  515. Person.Name = txtName.Text
  516. Person.Memo = txtMemo.Text
  517. pos = InStr(txtFname.Text, ".")
  518. If pos = 0 Then
  519.  Person.Fname = txtFname.Text
  520.  Person.Fext = ""
  521. ElseIf pos < 2 Then
  522.  Person.Fname = ""
  523.  Person.Fext = Mid$(txtFname.Text, 2)
  524. ElseIf pos < 3 Then
  525.  Person.Fname = Left$(txtFname.Text, 1)
  526.  Person.Fext = Mid$(txtFname.Text, pos + 1)
  527.  Person.Fname = Left$(txtFname.Text, 2)
  528.  Person.Fext = Mid$(txtFname.Text, pos + 1)
  529. End If
  530. 'Output record
  531. Put #FileNum, cboID.ListIndex + 1, Person
  532. 'Close file
  533. Close FileNum
  534. WRERRORID:
  535. Exit Sub
  536. End Sub
  537. Sub txtFname_LostFocus ()
  538. 'Save changes
  539. procWriteID
  540. End Sub
  541. Sub txtMemo_LostFocus ()
  542. 'Save changes
  543. procWriteID
  544. End Sub
  545.